<template>
  <el-dropdown @command="handleCommand">
    <span class="el-dropdown-link">
      {{ label || '请选择' }}
      <el-icon class="el-icon--right">
        <CaretBottom />
      </el-icon>
    </span>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item v-for="item in options" :key="item.label" :command="item.value">
          {{ item.label }}
        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>
<script setup>
const emits = defineEmits(['change'])
const value = defineModel({ type: String })
const props = defineProps({
  options: Array,
})

const handleCommand = command => {
  value.value = command
  emits('change')
}

const label = computed(() => {
  return props.options.find(item => item.value === value.value)?.label
})
</script>
<style lang="scss" scoped>
.el-dropdown-link {
  outline: none;
  cursor: pointer;
  color: var(--primary);
  padding-bottom: 12px;
}
</style>
